package com.example.design.patterns.冰河.行为模式.观察者模式.subject;

import com.example.design.patterns.冰河.行为模式.观察者模式.observer.Policeman;
import java.util.ArrayList;
import java.util.List;

/**
 * Subject(目标) 目标知道它的观察者.可以有任意多个观察者观察同一个目标.
 * 提供注册和删除观察者对象的接口.
 */
public abstract class Citizen {
    protected List<Policeman> pols;
    String help = "normal";

    public String getHelp() {
        return help;
    }

    public void setHelp(String help) {
        this.help = help;
    }

    public abstract void sendMessage(String help);

    public void setPolicemen() {
        this.pols = new ArrayList<>();
    }

    public void register(Policeman pol) {
        this.pols.add(pol);
    }

    public void unRegister(Policeman pol) {
        this.pols.remove(pol);
    }
}
